﻿//***********************************************************************
// Assembly         : IGolovkine.AoA.Tests
// Author           : Ilia
// Created          : 06-11-2011
//
// Last Modified By : Ilia
// Last Modified On : 01-04-2010
// Description      : 
//
// Copyright        : (c) Microsoft. All rights reserved.
//***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IGolovkine.AoA.Tests
{
    public class TestPacket
    {
        private readonly string _message;
        private readonly byte [] _data;
        
        public TestPacket(int repeat) 
        {
            StringBuilder buffer = new StringBuilder();
            for (int i = 0; i < repeat; i++)
            {
                buffer.Append(Guid.NewGuid().ToString());
            }
            _message = buffer.ToString();
            _data = System.Text.Encoding.Default.GetBytes(_message);
        }

        public TestPacket(string message)
        {
            _message = message;
            _data = System.Text.Encoding.Default.GetBytes(message);
        }
        public TestPacket(IEnumerable<byte> data)
        {
            byte[] array = data.ToArray();
            _data = array;
            _message = System.Text.Encoding.Default.GetString(array);
        }

        public byte[] GetData()
        {
            return _data;
        }

        public string Message
        {
            get { return _message; }
        }

        // override object.Equals
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            if (obj is string)
            {
                return string.Equals(_message, (string)obj, StringComparison.CurrentCulture);
            }

            if (obj is byte[])
            {
                //TestPacket packet = new TestPacket((byte[])obj);
                //return string.Equals(_data, packet._message);
            }

            if( obj is TestPacket ) 
            {
                return string.Equals(_message, ((TestPacket)obj)._message, StringComparison.CurrentCulture);
            }

            return false;
        }
        public override string ToString()
        {
            return _message;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
